const path = require('path');
const log4js = require('koa-log4');
const pathLogs = path.join(__dirname, "../logs")
log4js.configure({
    appenders: {
        access: {
            type: 'dateFile',
            pattern: '-yyyy-MM-dd.log', //生成文件的规则
            filename: path.join(pathLogs, 'access.log') //生成文件名
        },
        application: {
            type: 'dateFile',
            pattern: '-yyyy-MM-dd.log',
            filename: path.join(pathLogs, 'application.log')
        },
        out: {
            type: 'console'
        }
    },
    categories: {
        default: { appenders: ['out'], level: 'info' },
        access: { appenders: ['access'], level: 'info' },
        application: { appenders: ['application'], level: 'WARN' }
    }
});

const accessLogger = () => log4js.koaLogger(log4js.getLogger('access')); //记录所有访问级别的日志
const logger = log4js.getLogger('application'); //记录所有应用级别的日志
console.log("地址:", path.join('logs/', 'access.log'));

export {
    accessLogger,
    logger
}